/**
 * Created by Pin on 2014/6/24.
 */
$(function(){

	// things to do once the dom is ready
	// show users there's something on the bottom
	setTimeout(function(){
		$("#footer").removeClass('h').addClass('animated flipInY')	
	},1000);

    // pop up the diagram when link clicked
    $('.logreg').on('click', function () {
		// make distinction between login and register
		var btn = $(this).attr('id');
		console.log(btn)
		if ( 'loginlink' == btn ) {
			$('#logreg').find('h2').text('登入').end().find('#submitbtn').attr({'value':'进入我的秋荻'});
		}
		$('#logreg').show(300,function(){
			$('#logreg-form').removeClass('h').addClass('animated fadeInUp');
		});
    });
	
	
	// cancel logreg 
	$('.cancel-logreg').on('click', function(){
		$('#logreg').fadeOut(200);
		$('#logreg-form').addClass('h');
	});

    $('#start').on('click', function () {
     	$("#welcome").addClass("animated fadeOut")
    });

	// handle the register
	$('#logreg-form form').on('submit', function(event){
		event.preventDefault();
		var user = {
			name: $(this).find('input[name="email"]').val(),
			email: $(this).find('input[name="name"]').val(),
			password: $(this).find('input[name="password"]').val()
		};
		console.log(user);
		user.name = document.getElementById('logreg').innerHTML;
		$.post('/reg', user).done(function(data){
			console.log(data);	
			if( data.code == 200 ){
				console.log('register success');
			}
		});
	});
	
});
